package com.xiaofu.exception;


import com.xiaofu.utils.JsonData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class CustomExceptionHandler {

    @ExceptionHandler(BizException.class)
    public JsonData handleCustomException(BizException e) {
        log.error("[业务类异常 {}]", e.getMsg(),e);
        return JsonData.buildCodeAndMsg(e.getCode(), e.getMsg());
    }

    @ExceptionHandler(Exception.class)
    public JsonData handler(Exception e) {
        log.error("[系统类异常 {}]", e.getMessage(),e);
        return JsonData.buildError(e.getMessage());
    }

}
